package com.cwd.jobs;

import com.cwd.constant.RedisConstant;
import com.cwd.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

/**
 * @PackageName: com.cwd.jobs
 * @ClassName: ClearImgJob
 * @Author: CWD
 * @Date: 2020/3/5 13:02
 * @Description:
 */
//自定义Job类删除垃圾图片
public class ClearImgJob {
    @Autowired
    private JedisPool jedisPool;
    
    public void clearImg(){
        //获取redis数据库中两个表的差值
        Set<String> sdiffSet = jedisPool.getResource().sdiff(RedisConstant.SETMEAL_PIC_RESOURCES, RedisConstant.SETMEAL_PIC_DB_RESOURCES);
        //遍历集合
        if (sdiffSet != null) {
            for (String fileName : sdiffSet) {
                //删除七牛云平台中的垃圾图片
                QiniuUtils.deleteFileFromQiniu(fileName);
                //删除redis中垃圾图片
                jedisPool.getResource().srem(RedisConstant.SETMEAL_PIC_RESOURCES,fileName);
            }
        }
    }
}
